<template>
<div class="main_box">
  <div class="add_wrap">
    <div class="tit">
      <h2>基础信息</h2>
      <el-button plain size="small" type="success" icon="fa fa-mail-forward" @click="returnList"> 返 回</el-button>  
    </div>
    <el-form :model="dataForm" ref="dataForm" label-width="200px" :rules="roleRules">
      <el-row>
       <!-- <el-form-item label="建议/投诉" prop="adviceType">
          <el-select v-model="dataForm.adviceType" placeholder="请选择类型">
            <el-option
              v-for="item in adviceTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>-->
        <el-form-item label="联系人" prop="linkName">
          <el-input v-model="dataForm.linkName" clearable></el-input>
        </el-form-item>
        <el-form-item label="联系电话" prop="linkPhone">
          <el-input v-model="dataForm.linkPhone" clearable></el-input>
        </el-form-item>
        <el-form-item label="疾病类型" prop="diseasesType">
          <el-input v-model="dataForm.diseasesType" clearable></el-input>
        </el-form-item>
        <el-form-item label="学习内容" prop="content">
          <el-input
              placeholder="请输入内容"
              v-model="dataForm.content"
              type="textarea"
              autosize>
          </el-input>
        </el-form-item>
      </el-row>

      <el-row>
        <el-form-item>
          <el-button plain type="primary" @click="sureClick">保 存</el-button>
          <el-button @click="returnList">取 消</el-button>
        </el-form-item>
      </el-row>
    </el-form>
  </div>
 </div>
</template>

<script>
import * as message from "@/constants/message";
import Region from "@/components/Region";
import UserApi from "@/api/user/user";
export default{
  data(){
      return {
        dataForm:{
          adviceId: "",
          linkName: "",
          linkPhone: "",
          diseasesType: "",
          content: "",
          adviceType: 4
        },
        loadingIns:false,
        syUserId: null,
        syUserList: [],
        temperatureList: [],
        adviceTypeList: [
          { label: '建议', value: '1' },
          { label: '投诉', value: '2' }
        ],
        roleRules: {
          content: [
            { required: true, message: "请输入学习内容", trigger: "blur" },
            { max: 200, message: '长度不超过200个字', trigger: 'blur' }
          ],
          diseasesType: [
            {required: true, message: "请输入疾病类型", trigger: "blur"}
          ]
          /*adviceType:[
            {  required: true, message: "请选择类型", trigger: "change" }
          ]*/
        }
      }
  },
  components: {
    Region,
  },
  methods: {
    init(){
      if (this.$route.query.id) {
        this.dataForm.adviceId = this.$route.query.id
        this.getData()
      }
    },
    sureClick() {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          this.$confirm(message.MSG_CONFIRM_SUBMIT_APPLICATION, message.TITLE_PROMPT, {})
            .then(() => {
              if (this.dataForm.adviceId){
                this.editData();
              }else{
                this.addData();
              }
          });
        }
      })
    },
    addData() {
      UserApi.addUserAdvice(this.dataForm)
      .then(data => {
        this.$Utils.notifySuccess()
        this.returnList();
      })
    },
    editData() {
      UserApi.editUserAdvice(this.dataForm)
        .then(data => {
          this.$Utils.notifySuccess()
          this.returnList();
        })
    },
    getData () {
      UserApi.getUserAdviceInfo({adviceId: this.dataForm.adviceId})
        .then(res => {
          this.$Utils.bindingBean(this.dataForm, res.data)
          this.dataForm.adviceId = parseInt(res.data.adviceId);
          this.dataForm.adviceType = parseInt(res.data.adviceType);
        })
    },
    returnList(){
      this.$store.dispatch('delView', this.$route);
      this.$router.push({path: '/user/userStudyManagement'});
    }
  },
  mounted(){
    this.init()
  }
}
</script>
<style lang="scss" src="@/assets/css/views/add.scss" scope>
</style>
